<template>
  <div class="contract-payment">
    <!-- 列表查询区域 -->
    <el-card>
      <!-- 查询条件 -->
      <el-form :model="state.queryData" label-width="100px" class="query-form">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="工作号">
              <el-input v-model="state.queryData.JobNum" placeholder="请输入工作号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="客户编码">
              <el-input v-model="state.queryData.CustCode" placeholder="请输入客户编码"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="客户名称">
              <el-input v-model="state.queryData.CustName" placeholder="请输入客户名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="合同号">
              <el-input v-model="state.queryData.ContractNum" placeholder="请输入合同号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="状态">
              <el-select v-model="state.queryData.State" placeholder="请选择状态">
                <el-option label="开立" value="0"></el-option>
                <el-option label="已审核" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="制单日期">
              <el-date-picker
                v-model="state.queryData.dateRange"
                type="daterange"
                format="YYYY-MM-DD "
                value-format="YYYY-MM-DD"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-form-item>
            <el-button type="primary" @click="getData">查询</el-button>
            <el-button @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-row>
      </el-form>
      <div class="table-header">
        <div class="toolbar-buttons" style="display: flex;gap: 8px;justify-content: end;padding-bottom: 10px">
<!--          <el-button type="primary" @click="addHandle()" >新增</el-button>-->
<!--          <el-button type="primary" @click="handlEedit()" :disabled="!state.selectedRow" v-if="state.selectedRow?.State != 1">编辑</el-button>-->
<!--          <el-button type="danger" @click="deleteHandles" :disabled="!state.selectedRow" v-if="state.selectedRow?.State != 1">删除</el-button>-->
<!--          <el-button type="danger" @click="handlCheck()" :disabled="!state.selectedRow" v-if="state.selectedRow?.State != 1">审核</el-button>-->
<!--          <el-button type="danger" @click="handlUnCheck()" :disabled="!state.selectedRow" v-if="state.selectedRow?.State != 0">弃审</el-button>-->
          <el-button type="primary" @click="addHandle()" v-if="checkPermission('新增', state.roleList)">新增</el-button>
          <el-button type="primary" @click="handlEedit()" :disabled="!state.selectedRow" v-if="checkPermission('编辑', state.roleList) && state.selectedRow?.State != 1">编辑</el-button>
          <el-button type="danger" @click="deleteHandles" :disabled="!state.selectedRow" v-if="checkPermission('删除', state.roleList) && state.selectedRow?.State != 1">删除</el-button>
          <el-button type="danger" @click="handlCheck" :disabled="!state.selectedRow" v-if="checkPermission('审核', state.roleList) && state.selectedRow?.State != 1">审核</el-button>
          <el-button type="danger" @click="handlUnCheck" :disabled="!state.selectedRow" v-if="checkPermission('弃审', state.roleList) && state.selectedRow?.State != 0">弃审</el-button>

        </div>
      </div>

      <!-- 数据表格 -->
      <el-card>
        <el-table
            v-loading="state.loading"
            :data="state.table.data"
            style="width: 100%"
            border
            @selection-change="handleSelectionChange"
            :row-class-name="tableRowClassName"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="JobNum" label="工作号" width="120" fixed>
            <template #default="scope">
              <el-link type="primary" @click="viewCheck(scope.row)">{{ scope.row.JobNum }}</el-link>
            </template>
          </el-table-column>
          <el-table-column prop="CustCode" label="客户编码" width="110" ></el-table-column>
          <el-table-column prop="CustName" label="客户名称" width="180" show-overflow-tooltip></el-table-column>
          <el-table-column prop="ContractNum" label="合同号" width="140" show-overflow-tooltip></el-table-column>
          <el-table-column prop="ProjectName" label="项目名称" width="180" show-overflow-tooltip></el-table-column>
          <el-table-column prop="ContractAmount" label="合同金额" width="100" ></el-table-column>
          <el-table-column prop="FHAmount" label="发货金额" width="100" ></el-table-column>
          <el-table-column prop="YSAmount" label="应收金额" width="100" ></el-table-column>
          <el-table-column prop="HKAmount" label="回款金额" width="100" ></el-table-column>
          <el-table-column prop="DSAmount" label="待收金额" width="100" ></el-table-column>
          <el-table-column prop="DDAmount" label="订单金额" width="100" ></el-table-column>
          <el-table-column prop="ContractType" label="合同类型" width="100" ></el-table-column>
          <el-table-column prop="DeliveryDate" label="交货日期" width="120" >
            <template #default="scope">
              <span> {{parseTime(scope.row.DeliveryDate,'{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="CreateBy" label="制单人" width="100" ></el-table-column>
          <el-table-column prop="CreateTime" label="制单日期" width="120" >
            <template #default="scope">
              <span> {{parseTime(scope.row.CreateTime,'{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="State" label="状态" width="100">
            <template #default="scope">
              <el-tag type="info" v-if="scope.row.State === 0">开立</el-tag>
              <el-tag type="success" v-if="scope.row.State === 1">已审核</el-tag>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
            style="display: flex;justify-content: end;margin-top: 10px"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="state.pagination.currentPage"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="state.pagination.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="state.pagination.total">
        </el-pagination>
      </el-card>

    </el-card>

    <!-- 新增/修改弹窗 -->
    <el-dialog :title="state.title" width="60%" v-model="state.dialogVisible" draggable :close-on-click-modal="false">
      <el-form ref="formRef" :model="state.formData" :rules="state.rules" label-width="120px">
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="工作号" prop="JobNum">
              <JobNumberDropdown
                  :isUseGlobalData="false"
                  :disabled="state.formData.Id"
                  v-model="state.formData.JobNum"
                  @change="updateContarctInfo"
                  :contract-list="state.contractList"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合同名称" prop="ContractName">
              <el-input v-model="state.formData.ContractName" placeholder="请输入合同名称" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合同号" prop="ContractNum">
              <el-input v-model="state.formData.ContractNum" placeholder="请输入合同号" disabled></el-input>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="客户名称" prop="CustName">
              <el-input v-model="state.formData.CustName" placeholder="请输入客户名称" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合同金额" prop="ContractAmount">
              <el-input v-model="state.formData.ContractAmount" placeholder="请输入合同金额" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="项目名称" prop="ProjectName">
              <el-input v-model="state.formData.ProjectName" placeholder="请输入项目名称" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单金额" prop="DDAmount">
              <el-input v-model="state.formData.DDAmount" placeholder="请输入订单金额" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发货金额" prop="FHAmount">
              <el-input v-model="state.formData.FHAmount" placeholder="请输入发货金额" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发票金额" prop="FPAmount">
              <el-input v-model="state.formData.FPAmount" placeholder="请输入发票金额" disabled></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="应收金额" prop="YSAmount">
              <el-input v-model="state.formData.YSAmount" placeholder="请输入应收金额" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="总回款额" prop="AllAmount">
              <el-input v-model="state.formData.AllAmount" placeholder="请输入总回款额" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="待收金额" prop="DSAmount">
              <el-input v-model="state.formData.DSAmount" placeholder="请输入待收金额" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <!-- 合同明细表格 -->
      <el-card style="margin-top: 20px;">
        <template #header>
          <div class="card-header flex is-justify-space-between">
            <span>明细</span>
            <div>
              <el-button
                type="primary"
                size="small"
                @click="handleAddLine"
              >
                增行
              </el-button>
            </div>
          </div>
        </template>
        <el-table
          :data="state.clumTable.data"
          style="width: 100%"
          border
          show-summary
          :summary-method="getSummaries"
        >

          <el-table-column prop="Ddate" label="收款日期">
            <template #default="scope">
              <el-date-picker
                v-model="scope.row.Ddate"
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
                type="date"
                clearable
              ></el-date-picker>
            </template>
          </el-table-column>
          <el-table-column prop="Rtype" label="收款类型">
            <template #default="scope">
              <el-select
                  v-model="scope.row.Rtype"
                  filterable
                  remote
                  reserve-keyword
                  placeholder="请选择类型"
                  remote-show-suffix
                  style="width: 100%"
              >
                <el-option :label="item.Type" :value="item.Type" v-for="(item,index) in state.cusoptions" :key="index">
                  <span style="float: left">{{ item.Type }}</span>
                  <span style=" float: right;font-size: 13px;">
                    {{ item.TermContent }}
                  </span>
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column prop="SSAmount" label="收款金额" >
            <template #default="scope">
              <el-input
                v-model="scope.row.SSAmount"
                type="number"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="80">
            <template #default="scope">
              <el-button type="danger" size="small" @click="handleDelete(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-card>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="closeDialog">取消</el-button>
          <el-button type="primary" @click="submitForm">确定</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 详情弹窗 -->
    <el-dialog :title="'回款单详情'" width="60%" v-model="state.detailVisible" draggable :close-on-click-modal="false">
      <el-form ref="formRef" :model="state.detailData" disabled label-width="120px">
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="工作号" prop="JobNum">
              <el-input v-model="state.detailData.JobNum" placeholder="请输入工作号" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合同名称" prop="ContractName">
              <el-input v-model="state.detailData.ContractName" placeholder="请输入合同名称" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合同号" prop="ContractNum">
              <el-input v-model="state.detailData.ContractNum" placeholder="请输入合同号" disabled></el-input>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="客户名称" prop="CustName">
              <el-input v-model="state.detailData.CustName" placeholder="请输入客户名称" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="合同金额" prop="ContractAmount">
              <el-input v-model="state.detailData.ContractAmount" placeholder="请输入合同金额" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="项目名称" prop="ProjectName">
              <el-input v-model="state.detailData.ProjectName" placeholder="请输入项目名称" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单金额" prop="DDAmount">
              <el-input v-model="state.detailData.DDAmount" placeholder="请输入订单金额" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发货金额" prop="FHAmount">
              <el-input v-model="state.formData.FHAmount" placeholder="请输入发货金额" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发票金额" prop="FPAmount">
              <el-input v-model="state.detailData.FPAmount" placeholder="请输入发票金额" disabled></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="应收金额" prop="YSAmount">
              <el-input v-model="state.detailData.YSAmount" placeholder="请输入应收金额" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="总回款额" prop="AllAmount">
              <el-input v-model="state.detailData.AllAmount" placeholder="请输入总回款额" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="待收金额" prop="DSAmount">
              <el-input v-model="state.formData.DSAmount" placeholder="请输入待收金额" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <!-- 合同明细表格 -->
      <el-card style="margin-top: 20px;">
        <template #header>
          <div class="card-header flex is-justify-space-between">
            <span>明细</span>
          </div>
        </template>
        <el-table
            :data="state.detailGridData"
            style="width: 100%"
            border
            show-summary
            :summary-method="getSummaries"
        >
          <el-table-column prop="Ddate" label="收款日期">
            <template #default="scope">
              <span> {{parseTime(scope.row.Ddate,'{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="Rtype" label="收款类型"/>
          <el-table-column prop="SSAmount" label="收款金额" />
        </el-table>
      </el-card>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="state.detailVisible = false">关闭</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import {computed, onMounted, reactive, ref, toRefs} from 'vue';
import {
  CheckStateHtDateil,
  CheckStateUnHtDateil,
  DeleteHtDateil,
  GetHTDatas,
  GetOneHtDateil,
  SaveContractReturn,
  selcetList,
  UpdateContractReturn
} from '@/api/contract_payment';
import {userRole} from '@/api/base';
import {parseTime,checkPermission} from '@/utils/util';
import {cubasdocStore} from '@/stores/modules/cubasdoc';
import {ElMessage, ElMessageBox, ElNotification} from 'element-plus';
import JobNumberDropdown from "@/components/JobNumberDropdown/index.vue";

const cubasdoc = cubasdocStore();
const formRef = ref<any>(null);
const state = reactive({
  contractList:[],
  loading: false,
  queryData: {
    JobNum: null,
    CustCode: null,
    CustName: null,
    ContractNum: null,
    State: null,
    dateRange: null,
  },
  table: {
    data: [],
  },
  title: '新增回款单',
  dialogVisible: false,
  formData: {},
  rules: {
    JobNum: [
      { required: true, message: '请选择工作号', trigger: 'change' },
    ]
  },
  clumTable: {
    data: [],
  },
  editTable: {
    data: [],
  },
  cusoptions: [],
  selectedRow: null,
  detailVisible: false,
  detailData: {},
  detailGridData: [],
  roleList: [],
  coseData: [],
  pagination: {
    currentPage: 1, // 当前页
    pageSize: 10, // 每页显示条数
    total: 0, // 总条数
    layout: 'total,sizes,prev, pager, next, jumper', // 分页布局
  },
});

// 页面加载时初始化数据
onMounted(() => {
  getData();
  initRoleList();
});

// 最终参数获取
const getQueryData = computed(() => {
  const data = toRefs(state.queryData)
  console.log(data,"data.CustName?.value")
  let JobNum = {name: "JobNum", value: data.JobNum?.value,wheretype:'0'}
  let CustCode = {name: "CustCode", value: data.CustCode?.value,wheretype:'0'}
  let CustName = {name: "CustName", value: data.CustName?.value,wheretype:'0'}
  let ContractNum = {name: "ContractNum", value: data.ContractNum?.value,wheretype:'0'}
  let State = {name: "State", value: data.State?.value,wheretype:'0'}
  //转换查询参数
  let where=[]
  if(data.JobNum && data.JobNum?.value !==''&& data.JobNum?.value !==null){
    where.push(JobNum)
  }
  if(data.CustCode?.value && data.CustCode?.value !==''&& data.CustCode?.value !==null){
    where.push(CustCode)
  }
  if(data.CustName?.value && data.CustName?.value !==''&& data.CustName?.value !==null){
    where.push(CustName)
  }
  if(data.ContractNum?.value && data.ContractNum?.value !=='' && data.ContractNum?.value !==null){
    where.push(ContractNum)
  }
  if(data.State?.value && data.State?.value !=='' && data.State?.value !==null){
    where.push(State)
  }
  console.log(data.dateRange,"where")
  if(data.dateRange?.value && data.dateRange?.value !=='' && data.dateRange?.value !==null){
    let startTime ={name: "CreateTime", value: data.dateRange?.value[0],wheretype:'2'}
    let endTime ={name: "CreateTime", value: data.dateRange?.value[1],wheretype:'3'}
    where.push(startTime)
    where.push(endTime)
  }
  return {
    PageIndex: data.PageIndex?.value,
    PageSize : data.PageSize?.value,
    where
  }
})


// 获取数据列表
const getData = async () => {
  state.loading = true;
  try {
    state.queryData = {
      ...state.queryData,
      PageIndex: state.pagination.currentPage,
      PageSize: state.pagination.pageSize,
    };
    const data = await selcetList(getQueryData.value);
    if (data.Code === 200) {
      state.table.data = data.Data;
      state.pagination.total = data.Total;
    }
  } catch (error) {
    ElMessage.error('获取数据失败');
  } finally {
    state.loading = false;
  }
};

// 重置查询条件
const resetQuery = () => {
  state.queryData = {
    JobNum: null,
    CustCode: null,
    CustName: null,
    ContractNum: null,
    State: null,
    dateRange: null,
    PageIndex: 1,
    PageSize :  10, // 每页显示条数
  };
  getData()
};

const handleSelectionChange = (val: any[]) => {
  state.selectedRow = val.length === 1 ? val[0] : null
}


// 表格行样式
const tableRowClassName = ({ row }: { row: any }) => {
  return row.State === '3' ? 'row-disabled' : '';
};

// 查看详情
const viewCheck = async (row: any) => {
  try {
    const { Data } = await GetOneHtDateil({ id: row.Id });
    state.detailData = Data[0];
    state.detailGridData = Data[0].tails;
    state.detailVisible = true;
  } catch (error) {
    ElMessage.error('获取详情失败');
  }
};

// 编辑
const handlEedit = async () => {
  try {
    const { Data } = await GetOneHtDateil({ id: state.selectedRow.Id });
    state.formData = Data[0];
    state.clumTable.data = Data[0].tails;
    state.title = '修改回款单';
    state.dialogVisible = true;
  } catch (error) {
    ElMessage.error('获取编辑数据失败');
  }
};

// 删除
const deleteHandles = (row?: any) => {
  const ids = row?.Id ? [row.Id] : state.selectedRow ? [state.selectedRow.Id] : [];

  if (ids.length === 0) {
    ElMessage.warning('请选择要删除的数据');
    return;
  }

  ElMessageBox.confirm(
    '请仔细核对数据，删除后无法恢复！',
    '审核提示',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(async () => {
      try {
        await DeleteHtDateil({ id: state.selectedRow.Id });
        ElMessage.success('删除成功');
        await getData();
        state.selectedRow = null;
      } catch (error) {
        ElMessage.error('删除失败');
      }
    })
    .catch(() => {});
};

// 审核
const handlCheck = async () => {
  try {
    await CheckStateHtDateil({id:state.selectedRow.Id});
    ElMessage.success('审核成功');
    await getData();
    state.selectedRow = null;
  } catch (error) {
    ElMessage.error('审核失败');
  }
};
// 弃审
const handlUnCheck = async () => {
  try {
    await CheckStateUnHtDateil({id:state.selectedRow.Id});
    ElMessage.success('弃审成功');
    await getData();
    state.selectedRow = null;
  } catch (error) {
    ElMessage.error('弃审失败');
  }
};

// 新增
const addHandle = async() => {
  resetForm();
  let contractList =await GetHTDatas({})
  state.contractList = contractList.Data
  state.title = '新增回款单';
  state.dialogVisible = true;
};

// 关闭弹窗
const closeDialog = () => {
  resetForm();
  state.dialogVisible = false;
};

// 重置表单
const resetForm = () => {
  state.formData = {};
  state.clumTable.data = [];
  state.editTable.data = [];
  state.coseData = [];
  if (formRef.value) {
    formRef.value.resetFields();
  }
};

function updateContarctInfo (e) {
  //查询过滤合同信息
  if (e){
    console.log(e,"选择合同信息")
    //赋值项目名称
    state.formData.ContractName = e?.ContractName;
    state.formData.ContractNum = e?.ContractNum;
    state.formData.CustName = e?.CustName;
    state.formData.CustCode = e?.CustCode;
    state.formData.ProjectName = e?.ProjectName;
    state.formData.ContractAmount = e?.ContractAmount;
    state.formData.DDAmount = e?.ContractAmount;
    //调用查询合同详细信息
    state.cusoptions = e?.tremZFs
    // findContractInfo(e.Id)
  }
  else {
    state.clumTable.data = []
  }
}


// 选择合同
const selectionChange = (e: any[]) => {
  state.coseData = e;
};

// 删除合同明细
const handleDelete = (row: any) => {
  const index = state.clumTable.data.indexOf(row);
  if (index !== -1) {
    state.clumTable.data.splice(index, 1);
  }
};

// 提交表单
const submitForm = () => {
  formRef.value.validate(async (valid: boolean) => {
    if (valid) {
      if (state.clumTable.data.length <= 0) {
        ElMessage.warning('请增加明细');
        return;
      }

      try {
        const data = {
          ...state.formData,
          tails: state.clumTable.data,
        };
        const res = state.formData.Id ?  await UpdateContractReturn(data) :await SaveContractReturn(data);
        if (res.Code === 'OK') {
          ElNotification.success({
            title: '提示',
            message: '保存成功',
            offset: 200,
          });
          closeDialog();
          await getData();
          state.selectedRow = null;
        } else {
          ElNotification.error({
            title: '提示',
            message: res.Result,
            offset: 200,
          });
        }
      } catch (error) {
        ElMessage.error('保存失败');
      }
    }
  });
};

// 初始化角色列表
const initRoleList = async () => {
  try {
    const res = await userRole({ VT_ID: '合同回款单' });
    state.roleList = res.items;
  } catch (error) {
    ElMessage.error('获取角色权限失败');
  }
};

// 合计方法
const getSummaries = (param: any) => {
  const { columns, data } = param;
  const sums: any[] = [];
  columns.forEach((column: any, index: number) => {
    if (index === 0) {
      sums[index] = '合计';
      return;
    }
    if (column.prop === 'Amount' || column.prop === 'Tax' || column.prop === 'iNatAmount') {
      const values = data.map((item: any) => Number(item[column.prop]));
      if (!values.every((value: number) => isNaN(value))) {
        sums[index] = values.reduce((prev: number, curr: number) => {
          const value = Number(curr);
          if (!isNaN(value)) {
            return prev + value;
          } else {
            return prev;
          }
        }, 0);
        sums[index] = sums[index].toFixed(2);
      } else {
        sums[index] = '0.00';
      }
    } else {
      sums[index] = '';
    }
  });
  return sums;
};

const handleAddLine = () => {
  const quantity = {
    SSAmount: null,
    Ddate: parseTime(new Date(), '{y}-{m}-{d}'),
    Rtype: null
  };
  state.clumTable.data.push(quantity);
}

// 选择当前页码
const handleSizeChange = val => {
  state.pagination.pageSize = val;
  state.queryData.PageSize = val;
  getData()
}

// 选择当前页码
const handleCurrentChange = val => {
  state.pagination.currentPage = val;
  state.queryData.PageIndex= val
  getData()
}




</script>

<style scoped>

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header-buttons {
  display: flex;
  gap: 10px;
}

.query-form {
  margin-bottom: 20px;
}

.query-buttons {
  display: flex;
  gap: 10px;
  padding-top: 24px;
}

.row-disabled {
  color: #999;
  background-color: #f5f5f5;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
</style>
